package JUCHelperClass;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {
    public static void main(String[] args) {

        CyclicBarrier cyclicBarrier = new CyclicBarrier(20, () -> {
            System.out.println("=====出发去 三亚旅游。。。。");
        });

        for (int i = 1; i <= 20; i++) {
            final int temp = i;
            new Thread(() -> {
                //第⼏个⼈ 已报名...
                System.out.println("第" + temp + "个⼈ 已报名...");
                try {
                    cyclicBarrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }, String.valueOf(i)).start();
        }
    }
}